package com.atguigu.gmall.product.rpc;

import com.atguigu.gmall.common.result.Result;
import com.atguigu.gmall.product.service.BaseCategory1Service;
import com.atguigu.gmall.product.vo.CategoryTreeVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@RestController
@RequestMapping("/api/inner/rpc/product")
public class CategoryRpcController {

    @Autowired
    BaseCategory1Service baseCategory1Service;

    /**
     * 获取客户端界面的分类树
     * @return
     */
    @GetMapping("/category/tree")

    public Result<List<CategoryTreeVo>> getCategoryTree(){
        List<CategoryTreeVo> list = baseCategory1Service.getCategoryTree();
        return Result.ok(list);
    }

    /**
     * 根据三级分类Id获取整个分类路径
     * @param c3id
     * @return
     */
    @GetMapping("/category/view/{c3id}")
    public Result<CategoryTreeVo> getCateGoryTreeWithC3id(@PathVariable Long c3id){
        CategoryTreeVo categoryTreeVo = baseCategory1Service.getCateGoryTreeWithC3id(c3id);
        return Result.ok(categoryTreeVo);
    }
}
